<?php

/*

Adopt a pet (getpet.php)

*/

$rank_check = 1;
$page_title = "Adopt a pet";
include "header.inc.php";

if ($num_pets > 0)
{
	die(header(error("index.php?game=$game","You already have a pet.")));
}
$findPets2 = mysql_query("SELECT * FROM pets2 WHERE game = '$game'");
$numPets = mysql_num_rows($findPets2);
if ($numPets == "0")
{
	if ($rank == 7)
	{
		$ifAdmin = "<br>Admins: Click <a href=admin/admin_add_pet.php?game=$game>here</a> to add pets!";
	}
	die("$openHTML<p align=center><font size=+2>There are no pets to adopt yet.</font><font size=+1>$ifAdmin</font></p>$closeHTML");
}
else
{
	if (!$start) { $start = 0; }
	$start2 = $start + 3;
	$start3 = $start - 3;
	$findPets = mysql_query("SELECT * FROM pets2 WHERE game = '$game' AND starter = '1' ORDER BY id LIMIT $start,3");
	while ($getPets = mysql_fetch_array($findPets))
	{
		$threePets .= "<td><p align=center><a href=getpet.php?game=$game&species=$getPets[id]><img src=images/user_images/opg_$game/pets/pet_$getPets[id].gif><br>$getPets[name]</a></p></td>";
	}
}
if (!$species)
{
	if ($numPets > ($start + 3))
	{
		$nextThree = "<a href=getpet.php?game=$game&start=$start2>Next Three</a>";
	}
	else
	{
		$nextThree = "Next Three";
	}

	if (($start - 3) >= 0)
	{
		$previousThree = "<a href=getpet.php?game=$game&start=$start3>Previous Three</a>";
	}
	else
	{
		$previousThree = "Previous Three";
	}

	echo "$openHTML

	<p>What kind of pet would you like to adopt?</p>

	<table width=100%><tr>$threePets</tr></table>

	<p align=center>$previousThree | $nextThree</p>

	$closeHTML";
}

if ($species)
{
	$get_pet = fetch("SELECT * FROM pets2 WHERE id = '$species' AND game = '$game'");
	if (!$get_pet[id])
	{
		die(header(error("getpet.php?game=$game","Select a real pet.")));
	}
	else
	{
		echo $openHTML;
		echo "<p>What will you name your $get_pet[name]?</p><table align=center><tr><td><p align=center><img src=$base_url/images/user_images/opg_$game/pets/pet_$get_pet[id].gif><br><form action=$base_url/getpet.pro.php?game=$game method=post><input type=hidden name=species value=$get_pet[id] maxlength=16><input type=text size=16 name=petname><input type=submit name=submit value=Adopt></form></p></td></table>";
		echo $closeHTML;
	}
}

?>